package com.imooc.common.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by deng_wb on 2019/8/17
 */
public class SingleThreadPoolTest {
    public static void main(String[] args) {
        ExecutorService service = Executors.newSingleThreadExecutor(); //单线程线程池,保证任务的顺序性

        for (int i = 0; i < 5; i++) {
            final int j=i;
            service.execute(()->{
                System.out.println(j+"  "+Thread.currentThread().getName());
            });
        }
        service.shutdown();

    }

}
